package com.wyw.design.model.learning.behavioral.interpreter;

/**
 * @Title   非终结符，即我们的运算符构造类
 * @Description
 * @Author Mr Wu yewen.wu.china@gmail.com
 * @Date 2023/4/17 17:17
 * Update History:
 * Author        Time            Content
 */
public class NonTerminalExpression extends AbstractExpression {
    // 代表运算符两侧的参数，即a、b
    private AbstractExpression left;
    private AbstractExpression right;
    public NonTerminalExpression(AbstractExpression left, AbstractExpression right) {
        this.left = left;
        this.right = right;
    }
    @Override
    int interpreter(Context context) {
        // 实现具体的 a +b 的解释执行操作
        if (!context.getSymbol().equalsIgnoreCase("")) {
            return this.left.interpreter(context) + this.right.interpreter(context);
        }
        return 0;
    }
}
